<template>
  <BaseMainSlot>
    <template v-slot:btnsBar>
      <ActionBar
        :add-active="addActive"
        :del-active="delActive"
        :has-del="false"
        :page-no="164"
        @add="add"
        @del="del"
      />
    </template>
    <template v-slot:content>
      <e-table
        ref="tableData"
        rowKey="processTemplateId"
        :table-data="tableData"
        :table-columns="tableLabel"
        :page="currentPage"
        :size="pageSize"
        :total="totalSize"
        :loading="loading"
        :showSelectColumn="false"
        :table-option="tableOption"
        @sizeChange="changePageSize"
        @pageChange="changeCurrentPage"
        @tableUpdatePlus="mixTableUpdatePlus"
      >
        <template
          slot="audit"
          slot-scope="scoped"
          v-if="scoped.row.processTemplateId"
        >
          <el-radio-group
            v-model="scoped.row.audit"
            @change="auditStu($event, scoped.row)"
          >
            <el-radio :label="true">是</el-radio>
            <el-radio :label="false">否</el-radio>
          </el-radio-group>
        </template>
        <template
          slot="handle"
          slot-scope="scoped"
          v-if="scoped.row.processTemplateId"
        >
          <el-radio-group
            v-model="scoped.row.handle"
            @change="handleStu($event, scoped.row)"

          >
            <el-radio
            :disabled="scoped.row.processNodeType === '报废'"
            :label="true">是</el-radio>
            <el-radio
            v-if="scoped.row.processNodeType !== '报废'"
            :disabled="scoped.row.processNodeType === '报废'"
             :label="false">否</el-radio>
          </el-radio-group>
        </template>
        <template
          slot="operate"
          slot-scope="scoped"
          v-if="scoped.row.processTemplateId"
        >
          <span>
            <span
              class="table-btns-box"
              v-if="scoped.row.audit&&judgePermission(148,'stop')"
              @click="edit(scoped.row, 'process')"
            >
              <i class="el-icon-user-solid"></i>
              <span>审核人</span>
            </span>

            <span
              class="table-btns-box"
              v-if="scoped.row.handle&&judgePermission(148,'start')"
              @click="edit(scoped.row, 'Handle')"
            >
              <i class="el-icon-user"></i>
              <span>处理人</span>
            </span>
          </span>
        </template>
      </e-table>

      <AddEditDialog
        ref="addEditDialog"
        :now-chance-stau="nowChanceStau"
        :title-text="titleText"
        :edit-object="editObject"
        :show.sync="showAddEditDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
      <AddNodeConfigDialog
        ref="addNodeConfigDialog"
        :now-chance-stau="nowChanceStau"
        :title-text="titleText"
        :edit-object="editObject"
        :show.sync="showAddNodeConfigDialog"
        @closeDialog="() => {
          showAddNodeConfigDialog = false;
          queryPageList();
          closeDialog();
        }"
        @cancelDialog="() => {
          showAddNodeConfigDialog = false;
          cancel();
        }"
      />
    </template>
  </BaseMainSlot>
</template>

<script>
import ActionBar from "@/components/ActionBar";
import AddEditDialog from "./components/add-edit-dialog.vue";
import AddNodeConfigDialog from "./components/edit-nodeConfig-dialog.vue";
import nodeConfigApi from "@/api/equip-repair-manage/node-config";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new.vue";
import { mymixin } from "@/utils/mixin";
import { mapGetters } from "vuex";

export default {
  name: "RepairType",
  components: { BaseMainSlot, AddEditDialog, AddNodeConfigDialog, ActionBar },
  mixins: [mymixin],
  data() {
    return {
      // 所搜条件：类型名称
      groupName: "",
      // checkedIdList: [],
      // 表单展示项
      tableLabel: [
        {
          label: "节点类型",
          param: "processNodeType",
          show: true,
          notSearch: true,
        },
        {
          label: "是否审核",
          param: "audit",
          slotName: "audit",
          show: true,
          notSearch: true,
        },
        {
          label: "是否处理",
          param: "handle",
          slotName: "handle",
          show: true,
          notSearch: true,
        },
      ],

      // 表单事件
      tableOption: {
        label: "操作",
        width: "300",
        options: [
          {
            label: "操作",
            type: "text",
            icon: "el-icon-edit-outline",
            methods: "operate",
            slotName: "operate",
          },
        ],
      },
      showAddNodeConfigDialog: false,
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission",
    }),
  },
  watch: {},
  created() {
    this.queryPageList();
  },
  mounted() {},
  methods: {
    queryPageList(e) {
      this.loading = false;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {
          // organizationNo: sessionStorage.organizationNo,
          // category: "STATE",
          ...e,
        },
      };
      nodeConfigApi.queryPageList(params).then((res) => {
        this.loading = false;
        if (res.code === 1) {
          let data = res.data;
          // 赋值总条数
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },

    auditStu(e, f) {
      this.$confirm("确认修改该状态?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(() => {
          // if (!audit) {

          // }
          nodeConfigApi
            .edit({
              ...f,
              audit: e,
            })
            .then((res) => {
              if (res.code === 1) {
                this.$message.success(res.msg || "修改成功！");
                this.queryPageList();
                this.close();
              } else {
                this.$message.error(res.msg);
              }
            });
        })
        .catch(() => {
          this.$set(f, "audit", !e);
          this.$message({
            type: "info",
            message: "已取消修改",
          });
        });
    },
    handleStu(e, f) {
      this.$confirm("确认修改该状态?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(() => {
          // if (!audit) {

          // }
          nodeConfigApi
            .edit({
              ...f,
              handle: e,
            })
            .then((res) => {
              if (res.code === 1) {
                this.$message.success(res.msg || "修改成功！");
                this.queryPageList();
                this.close();
              } else {
                this.$message.error(res.msg);
              }
            });
        })
        .catch(() => {
          this.$set(f, "handle", !e);
          this.$message({
            type: "info",
            message: "已取消修改",
          });
        });
    },
    // 修改
    edit(row, e) {
      // if (row.sort) {
      this.editObject = JSON.parse(JSON.stringify({ ...row, type: e }));
      this.nowChanceStau = "edit";
      this.titleText = "修改";
      // this.addActive = false;
      // this.delActive = false;
      this.showAddNodeConfigDialog = true;
      // } else {
      //   this.editObject = {};
      // }
    },
    // 启用
    start(data) {
      this.$confirm("确认启用该节点?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(() => {
          var form = {
            audit: true,
            auditor: data.auditor,
            repairNodeName: data.repairNodeName,
            jumpNode: data.jumpNode,
            groupName: data.groupName,
            sort: data.sort,
            repairNodeId: data.repairNodeId,
            organizationMark: sessionStorage.organizationNo,
          };
          nodeConfigApi.edit(form).then((res) => {
            if (res.code === 1) {
              this.$message.success(res.msg);
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 停用
    stop(data) {
      this.$confirm("确认停用该节点?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(() => {
          var form = {
            audit: false,
            auditor: data.auditor,
            repairNodeName: data.repairNodeName,
            jumpNode: data.jumpNode,
            groupName: data.groupName,
            sort: data.sort,
            repairNodeId: data.repairNodeId,
            organizationMark: sessionStorage.organizationNo,
          };
          nodeConfigApi.edit(form).then((res) => {
            if (res.code === 1) {
              this.$message.success(res.msg);
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // selectAll(list) {
    //   let notvalue = true
    //   let notvalue1 = true
    //   list.forEach(item => {
    //     var index = this.noDelList.findIndex(a => a === item.jumpNode)
    //     if (index === -1) {
    //       if (!item.jumpNode) {
    //         notvalue = false
    //       }
    //     } else {
    //       notvalue1 = false
    //     }
    //   });
    //   if (notvalue === false && notvalue1 === true) {
    //     this.$message.warning("不可选择空数据！");
    //   } else if (notvalue1 === false && notvalue === true) {
    //     this.$message.warning("类型已被使用，请勿删除！");
    //   } else if (notvalue1 === false && notvalue === false) {
    //     this.$message.warning("类型已被使用，请勿删除！，不可选择空数据！");
    //   }
    // },
    // select(list) {
    //   let notvalue = true
    //   let notvalue1 = true
    //   list.forEach(item => {
    //     var index = this.noDelList.findIndex(a => a === item.jumpNode)
    //     if (index === -1) {
    //       if (!item.jumpNode) {
    //         notvalue = false
    //       }
    //     } else {
    //       notvalue1 = false
    //     }
    //   });
    //   if (notvalue === false && notvalue1 === true) {
    //     this.$message.warning("不可选择空数据！");
    //   } else if (notvalue1 === false && notvalue === true) {
    //     this.$message.warning("类型已被使用，请勿删除！");
    //   } else if (notvalue1 === false && notvalue === false) {
    //     this.$message.warning("类型已被使用，请勿删除！，不可选择空数据！");
    //   }
    // },
    // handleSelectionChange(list) {
    //   this.checkedIdList = [];
    //   let notvalue = true
    //   let emptyList = []
    //   this.checkedIdList = list.map(item => {
    //     var index = this.noDelList.findIndex(a => a === item.jumpNode)
    //     if (index === -1) {
    //       if (item.jumpNode) {
    //         return item.jumpNode
    //       } else {
    //         notvalue = false
    //         emptyList.push(item)
    //         return ""
    //       }
    //     } else {
    //       // this.$message.warning("该辖区已被绑定，若想删除，请先解绑！");
    //       this.toggleNoSelection([item])
    //       return
    //     }
    //   });
    //   if (notvalue === false) {
    //     // this.$message.warning("不可选择空数据！");
    //     this.toggleNoSelection(emptyList)
    //     return
    //   }
    //   if (this.checkedIdList.length >= 1) this.delActive = true;
    //   else this.delActive = false;
    // },

    // // 单个删除
    // delOne(data) {
    //   var index = this.noDelList.findIndex(a => a === data.jumpNode)
    //   if (index === -1) {
    //     this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning",
    //       customClass: "myClass"
    //     })
    //       .then(() => {
    //         var form = new FormData()
    //         form.append('jumpNodeList', data.jumpNode)
    //         repairTypeApi.delList(form).then(res => {
    //           if (res.code === 1) {
    //             this.$message.success(res.msg);
    //             this.queryPageList();
    //             this.resetActionBar();
    //           }
    //         });
    //       })
    //       .catch(() => {
    //         this.$message({
    //           type: "info",
    //           message: "已取消删除"
    //         });
    //       });
    //   }
    // },
    // // 表格删除
    // delmessage() {
    //   var form = new FormData()
    //   this.checkedIdList.forEach(a => {
    //     form.append('jumpNodeList', a)
    //   })
    //   repairTypeApi.delList(form).then(res => {
    //     if (res.code === 1) {
    //       this.$message.success(res.msg);
    //       this.queryPageList();
    //       this.resetActionBar();
    //     }
    //   });
    // },
    // // 添加
    // add() {
    //   this.nowChanceStau = 'add'
    //   this.titleText = "添加"
    //   this.addActive = false;
    //   this.delActive = false;
    //   this.editActive = false;
    //   this.showAddEditDialog = true
    // },
    // // 修改
    // edit(row) {
    //   if (row.jumpNode) {
    //     this.editObject = JSON.parse(JSON.stringify(row));
    //     this.nowChanceStau = 'edit'
    //     this.titleText = "修改"
    //     this.addActive = false;
    //     this.delActive = false;
    //     this.showAddEditDialog = true
    //   } else {
    //     this.editObject = {};
    //   }
    // }
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-radio-group {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .el-radio__input.is-checked .el-radio__inner {
    border-color: #54dee2;
    background: #54dee2;
  }
  .el-radio__input.is-checked + .el-radio__label {
    color: #54dee2;
  }
}
</style>
